/**
 * jims
 */
package com.jims.master.modules.oper.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jims.master.modules.oper.entity.ClinicVsCharge;
import com.jims.master.modules.oper.service.ClinicVsChargeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;

/**
 * 诊疗项目与价表对照Controller
 * @author 赵宁
 * @version 2017-02-23
 */
@Controller
@RequestMapping(value = "${adminPath}/oper/clinicVsCharge")
public class ClinicVsChargeController extends BaseController {

	@Autowired
	private ClinicVsChargeService clinicVsChargeService;
	
/*	@ModelAttribute
	public ClinicVsCharge get(@RequestParam(required=false) String id) {
		ClinicVsCharge entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = clinicVsChargeService.get(id);
		}
		if (entity == null){
			entity = new ClinicVsCharge();
		}
		return entity;
	}*/
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(ClinicVsCharge clinicVsCharge, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ClinicVsCharge> page = clinicVsChargeService.findPage(new Page<ClinicVsCharge>(request, response), clinicVsCharge); 
		model.addAttribute("page", page);
		return "modules/sys/clinicVsChargeIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(ClinicVsCharge clinicVsCharge, Model model) {
		model.addAttribute("clinicVsCharge", clinicVsCharge);
		return "modules/sys/clinicVsChargeForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(ClinicVsCharge clinicVsCharge) {
	    StringData data=new StringData();
		int i=clinicVsChargeService.save(clinicVsCharge);
        if(i>0){
            data.setCode("success");
            data.setData("保存诊疗项目与价表对照成功");
        }else{
            data.setCode("error");
            data.setData("保存诊疗项目与价表对照失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(ClinicVsCharge clinicVsCharge) {
	    StringData data=new StringData();
		int i=clinicVsChargeService.deleteByChargeId(clinicVsCharge);
        if(i>0){
            data.setCode("success");
            data.setData("删除诊疗项目与价表对照成功");
        }else{
            data.setCode("error");
            data.setData("删除诊疗项目与价表对照失败");
        }
		return data;
	}

}